package de.fhtrier.gdw2.ships.network.datagrams;

import de.fhtrier.gdw.commons.netcode.datagram.INetDatagram;
import de.fhtrier.gdw.commons.netcode.datagram.NetDatagram;
import de.fhtrier.gdw.commons.netcode.message.INetMessageIn;
import de.fhtrier.gdw.commons.netcode.message.INetMessageOut;

public final class ConnectDatagram extends NetDatagram {
	
	private String playerName = new String();

	public ConnectDatagram(byte type, short id, short param1, short param2) {
		super(INetDatagram.MessageType.DELTA, type, id, param1, param2);
	}
	
	public ConnectDatagram(String playerName) {
		super(INetDatagram.MessageType.DELTA, DatagramType.CONNECT, (short)0, (short)0, (short)0);
		
		this.playerName = playerName;
	}
	
	@Override
	public void writeToMessage(INetMessageOut message) {
		message.putString(playerName);
	}
	
	public @Override
	void readFromMessage(INetMessageIn message) {
		playerName = message.getString();
	}


	/**
	 * @return the player name
	 */
	public String getPlayerName() {
		return playerName;
	}
}